package com.hopedove.workshop.repository

import com.hopedove.workshop.api.WorkshopLoginData
import com.hopedove.workshop.data.WorkshopUserInfo
import com.hopedove.workshop.data.WorkshopUserSession
import com.hopedove.workshop.data.WorkshopUserSessionManager

class WorkshopUserRepository(private val userSessionManager: WorkshopUserSessionManager) {


    fun userLogin(loginInfo: WorkshopLoginData) {
        val info = WorkshopUserInfo(
            id = loginInfo.id,
            employeeNo = loginInfo.accountNo,
            accountName = loginInfo.account,
            realName = loginInfo.name
        )
        userSessionManager.login(info, true)
    }

    fun logout() {
        userSessionManager.logout()
    }

    fun getSignedUserSession(): WorkshopUserSession? {
        return userSessionManager.getUserSession()
    }

    fun getSignedInUserName(): String? {
        val session = userSessionManager.getUserSession() ?: return null
        return session.userName
    }

}